package edu.hit.pact.pgse.crawler.bbs;

import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Date;
import java.util.List;

public class BBSUnit implements Serializable{
	private URL url;
	private List<String> topicPrefixs;
	private List<String> articlePrefixs;
	private int maxNum;
	
	private Date dateTime;
	
	public BBSUnit(URL url, List<String> articlePrefixs, int maxNum) {
		super();
		this.url = url;
		this.topicPrefixs = topicPrefixs;
		this.articlePrefixs = articlePrefixs;
		this.maxNum = maxNum;
	}
    
	
	
	public BBSUnit() {
		super();
	}



	public URL getUrl() {
		return url;
	}

	public List<String> getTopicPrefixs() {
		return topicPrefixs;
	}

	public List<String> getArticlePrefixs() {
		return articlePrefixs;
	}

	public int getMaxNum() {
		return maxNum;
	}
	
	public boolean isTopicURL(URL url) {
		String link = url.toString();
		for (String prefix : topicPrefixs) {
			if (link.startsWith(prefix)) {
				return true;
			}//end if
		}//end for
		return false;
	}
	
	
	
	public void setUrl(URL url) {
		this.url = url;
	}

	public boolean isArticleURL(URL url,String subitem) {
		TianYaBBSURLFilter filter = new TianYaBBSURLFilter();
		return filter.isTianyaBbsArticleUrl(url,subitem);
		/**** add notation by HCZ 2010.11.6
		String link = url.toString();
		for (String prefix : articlePrefixs) {
			if (link.startsWith(prefix)) {
				return true;
			}//end if
		}//end for
		return false;
		
		*/
	}
	
	public boolean isNextPageUrl(URL judgeUrl,String subitem,int pageno){
		//System.out.println(judgeUrl.toExternalForm());
		TianYaBBSURLFilter filter = new TianYaBBSURLFilter();
		return filter.isTinayaNextPageUrl(judgeUrl, pageno, subitem);
	}

	@Override
	public String toString() {
		return "BBSUnit [articlePrefixs=" + articlePrefixs + ", maxNum="
				+ maxNum + ", topicPrefixs=" + topicPrefixs + ", url=" + url
				+ "]";
	}
	

	public static void main(String[] args){
		BBSUnit unit = new BBSUnit();
		URL tmpUrl = null;
		try {
			tmpUrl = new URL("http://www.tianya.cn/publicforum/articleslist/0/develop.shtml");
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		unit.setUrl(tmpUrl);
		URL desUrl = null;
		try {
			desUrl = new URL("http://www.tianya.cn/new/publicforum/articleslist.asp?pageno=1&stritem=develop&part=0&nextarticle=2010%2D11%2D6+14%3A52%3A14&strsubitem=&strsubitem2=");
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//System.out.println(unit.isNextPageUrl(desUrl));
		
	}
	
	
}
